package app

import (
	"github.com/slclub/go-tips"
)

type Scope struct {
	ScopeID    int    `gorm:"primaryKey;column:scope_id;autoIncrement"`
	ScopeType  string `gorm:"size:32;comment:权限类型 path=站内路径api, url=完整url地址"` // path 站内路径 url外部或内部url
	ScopeValue string `gorm:"size:255;comment:权限，如:具体的url"`
	State      int    `gorm:"type:int(4);comment:1生效，0失效"`
}

func (self *Scope) ConvFromMap(m map[string]any) {
	if val, ok := m["ScopeID"]; ok && self.ScopeID == 0 {
		self.ScopeID = tips.Int(val)
	}
	if val, ok := m["ScopeType"]; ok {
		self.ScopeType = tips.String(val)
	}
	if val, ok := m["ScopeValue"]; ok {
		self.ScopeValue = tips.String(val)
	}
	if val, ok := m["State"]; ok {
		self.State = tips.Int(val)
	}
}

func (self *Scope) ConvToMap() map[string]any {
	return map[string]any{
		"ScopeID":    self.ScopeID,
		"ScopeType":  self.ScopeType,
		"ScopeValue": self.ScopeValue,
		"State":      self.State,
	}
}
